$(document).ready(function () {
// 获取弹窗参数hasWarningLayer
    var hasWarningLayer = getCookie('hasWarningLayer') ? getCookie('hasWarningLayer') : 0;
    var content = '';
    var content1 = '可能出现队列服务崩溃，请立即联系技术人员处理或重启队列服务。</span><span>重启命令：</br>#supervisorctl stop all</br>#supervisorctl shutdown</br>#supervisord</span>';
    var content2 = '可能出现队列服务崩溃，请立即联系技术人员处理或重启队列服务。</span><span>重启命令：</br>#/data/xunsearch/bin/xs-ctl.sh restart</br>(其中/data/xunsearch/指的是讯搜的安装目录)</span>';
    getReportData(getReportDataUrl);
    canWarningLayer(hasWarningLayer, content, content1, content2);

    //队列弹窗
    $('.jobWarning').click(function () {
        var content = '<span>';
        var untreatedJob = $('#untreatedJob').attr('value');
        var warningJob = $('#warningJob').attr('value');
        if (untreatedJob == 1) {
            content += '您的未处理队列大于' + threshold + '条，';
        }
        if (warningJob == 1) {
            content += '您的错误队列大于' + threshold + '条，';
        }
        content += content1;
        warningLayer(content);
    });

    //迅搜弹窗
    $('.xsWarning').click(function () {
        content = '<span>';
        var xsJob = $('#xsJob').attr('value');
        var xsResume = $('#xsResume').attr('value');
        if (xsJob == 1) {
            content += '您的迅搜职位偏差大于' + threshold + '条，';
        }
        if (xsResume == 1) {
            content += '您的迅搜简历偏差大于' + threshold + '条，';
        }
        content += content2;
        warningLayer(content);
    });
});

//判断是否需要弹窗
function canWarningLayer(hasWarningLayer, content, content1, content2) {
    if (hasWarningLayer == 1) return false;
    var hasJob = 0;
    var untreatedJob = $('#untreatedJob').attr('value');
    var warningJob = $('#warningJob').attr('value');
    if (untreatedJob == 1 || warningJob == 1) {
        content = '<span>';
        hasJob = 1;
    }
    if (untreatedJob == 1) {
        content += '您的未处理队列大于' + threshold + '条，';
    }
    if (warningJob == 1) {
        content += '您的错误队列大于' + threshold + '条，';
    }
    if (hasJob == 1) {
        content += content1;
    }
    var hasXs = 0;
    if (xs == 1) {
        var xsJob = $('#xsJob').attr('value');
        var xsResume = $('#xsResume').attr('value');
        if (xsJob == 1 || xsResume == 1) {
            content += '<span>';
            hasXs = 1;
        }
        if (xsJob == 1) {
            content += '您的迅搜职位偏差大于' + threshold + '条，';
        }
        if (xsResume == 1) {
            content += '您的迅搜简历偏差大于' + threshold + '条，';
        }
        if (hasXs == 1) {
            content += content2;
        }
    }
    if (hasJob == 1 || hasXs == 1) {
        setCookie('hasWarningLayer', 1, 1);
        warningLayer(content);
    }
}

//弹窗操作
function warningLayer(content) {
    layer.open({
        type: 1,
        title: '<b>警告</b>',
        skin: 'layer-system-warning',
        area: ['400px'],
        resize: false,
        move: false,
        btn: ['知道了'],
        content: content
    });
}

//获取报表数据
function getReportData(getReportDataUrl) {
    $.post(getReportDataUrl, {
        '_token': csrf_token
    }, function(data){
        if(data.status == 0){
            var time_arr = data.data.time_arr;
            $.each(data.data.report_data, function (i, n) {
                reportShow(time_arr, i, data.data.report_name[i], n);
            });
        }else{
            layer.msg('报表获取失败，请刷新页面', {icon: 5});
        }
    });
}

//显示报表
function reportShow(time_arr, id_name, name, data) {
    var myChart = echarts.init(document.getElementById(id_name));
    var option = {
        title: {
            left: 'center',
            text: name
        },
        tooltip: {
            trigger: 'axis'
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: time_arr
        },
        yAxis: {
            minInterval: 1,
            splitNumber: 1,
            type: 'value'
        },
        series: [
            {
                name: '数量',
                type: 'line',
                data: data
            }
        ]
    };
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
}